/*
 ***************************************************************************************
 * 
 * @Title:  Count.java   
 * @Package io.github.junxworks.junx.stat.function.count   
 * @Description: (用一句话描述该文件做什么)   
 * @author: Michael
 * @date:   2018-7-12 20:49:28   
 * @version V1.0 
 * @Copyright: 2018 JunxWorks. All rights reserved. 
 * 
 *  ---------------------------------------------------------------------------------- 
 * 文件修改记录
 *     文件版本：         修改人：             修改原因：
 ***************************************************************************************
 */
package io.github.junxworks.junx.stat.function.desc;

import java.util.Collection;

import io.github.junxworks.junx.stat.StatContext;
import io.github.junxworks.junx.stat.function.BaseFunction;

/**
 * 检测数值集合是否以降序排序
 *
 * @author: Michael
 * @date:   2023-9-20 14:25:01
 * @since:  v1.0
 */
public class Desc extends BaseFunction {

	/**
	 * @see io.github.junxworks.junx.stat.function.StatFunc#getValue(long)
	 */
	@Override
	public Object getValue(Collection<?> collection, StatContext context) throws Exception {
		Double[] array = collection.toArray(new Double[0]);
		Double last = null;
		for (int i = 0, len = array.length; i < len; i++) {
			Double current = array[i];
			if (last == null) {
				last = current;
			}
			if (last < current) {
				return false;
			}
			last = current;
		}
		return true;
	}

}
